<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>tree - ClueLib</title><link rel="stylesheet" type="text/css" href="../styles/main.css"><script language=JavaScript src="../javascript/main.js"></script><script language=JavaScript src="../javascript/prettify.js"></script></head><body class="FramedContentPage" onLoad="NDOnLoad();prettyPrint();"><script language=JavaScript><!--
if (browserType) {document.write("<div class=" + browserType + ">");if (browserVer) {document.write("<div class=" + browserVer + ">"); }}// --></script>

<!--  Generated by Natural Docs, version 1.52 -->
<!--  http://www.naturaldocs.org  -->

<!-- saved from url=(0026)http://www.naturaldocs.org -->




<div id=Content><div class="CClass"><div class=CTopic id=MainTopic><h1 class=CTitle><a name="tree"></a>tree</h1><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>class tree #(</td><td class="PType  prettyprint " nowrap>type&nbsp;</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> int</td><td class="PAfterParameters  prettyprint "nowrap>) extends collection#( T )</td></tr></table></td></tr></table></blockquote><p>Implements a tree structure.</p><h4 class=CHeading>Parameter</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>T</td><td class=CDLDescription><span class="optional">optional</span> The type of data collected in a tree.&nbsp; The default is <b>int</b>.</td></tr></table><!--START_ND_SUMMARY--><div class=Summary><div class=STitle>Summary</div><div class=SBorder><table border=0 cellspacing=0 cellpadding=0 class=STable><tr class="SMain"><td class=SEntry><a href="#tree" id=link1 onMouseOver="ShowTip(event, 'tt1', 'link1')" onMouseOut="HideTip('tt1')">tree</a></td><td class=SDescription>Implements a tree structure.</td></tr><tr class="SGroup SIndent1"><td class=SEntry><a href="#tree.Types" >Types</a></td><td class=SDescription></td></tr><tr class="SType SIndent2 SMarked"><td class=SEntry><a href="#tree.tree_node_type" id=link2 onMouseOver="ShowTip(event, 'tt2', 'link2')" onMouseOut="HideTip('tt2')">tree_node_type</a></td><td class=SDescription>The shorthand of the <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link3 onMouseOver="ShowTip(event, 'tt3', 'link3')" onMouseOut="HideTip('tt3')">tree_node</a> type specialized with type <b>T</b>.</td></tr><tr class="SType SIndent2"><td class=SEntry><a href="#tree.tree_type" id=link4 onMouseOver="ShowTip(event, 'tt4', 'link4')" onMouseOut="HideTip('tt4')">tree_type</a></td><td class=SDescription>The shorthand of the <a href="#tree" class=LClass id=link5 onMouseOver="ShowTip(event, 'tt1', 'link5')" onMouseOut="HideTip('tt1')">tree</a> type specialized with type <b>T</b>.</td></tr><tr class="SGroup SIndent1"><td class=SEntry><a href="#tree.Properties" >Properties</a></td><td class=SDescription></td></tr><tr class="SProperty SIndent2 SMarked"><td class=SEntry><a href="#tree.root" id=link6 onMouseOver="ShowTip(event, 'tt5', 'link6')" onMouseOut="HideTip('tt5')">root</a></td><td class=SDescription>The root node of the tree.</td></tr><tr class="SGroup SIndent1"><td class=SEntry><a href="#tree.Functions" >Functions</a></td><td class=SDescription></td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#tree.new" id=link7 onMouseOver="ShowTip(event, 'tt6', 'link7')" onMouseOut="HideTip('tt6')">new</a></td><td class=SDescription>Creates a new tree.</td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#tree.add" id=link8 onMouseOver="ShowTip(event, 'tt7', 'link8')" onMouseOut="HideTip('tt7')">add</a></td><td class=SDescription><span class="virtual">virtual</span> Creates a new <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link9 onMouseOver="ShowTip(event, 'tt3', 'link9')" onMouseOut="HideTip('tt3')">tree_node</a> of the given element and adds it to the <a href="#tree.root" class=LProperty id=link10 onMouseOver="ShowTip(event, 'tt5', 'link10')" onMouseOut="HideTip('tt5')">root</a>. </td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#tree.add_to_node" id=link11 onMouseOver="ShowTip(event, 'tt8', 'link11')" onMouseOut="HideTip('tt8')">add_to_node</a></td><td class=SDescription><span class="virtual">virtual</span> Creates a new <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link12 onMouseOver="ShowTip(event, 'tt3', 'link12')" onMouseOut="HideTip('tt3')">tree_node</a> of the given element and adds it to the tree as the child of the specified parent.</td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#tree.graft" id=link13 onMouseOver="ShowTip(event, 'tt9', 'link13')" onMouseOut="HideTip('tt9')">graft</a></td><td class=SDescription><span class="virtual">virtual</span> Grafts the given <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link14 onMouseOver="ShowTip(event, 'tt3', 'link14')" onMouseOut="HideTip('tt3')">tree_node</a> (and its children) to the tree as the child of the specified parent.</td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#tree.clear" id=link15 onMouseOver="ShowTip(event, 'tt10', 'link15')" onMouseOut="HideTip('tt10')">clear</a></td><td class=SDescription><span class="virtual">virtual</span> Removes all of the elements from this tree.</td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#tree.clone" id=link16 onMouseOver="ShowTip(event, 'tt11', 'link16')" onMouseOut="HideTip('tt11')">clone</a></td><td class=SDescription><span class="virtual">virtual</span> Returns a shallow copy of this tree. </td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#tree.is_empty" id=link17 onMouseOver="ShowTip(event, 'tt12', 'link17')" onMouseOut="HideTip('tt12')">is_empty</a></td><td class=SDescription><span class="virtual">virtual</span> Returns 1 if this tree contains no elements.</td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#tree.get_iterator" id=link18 onMouseOver="ShowTip(event, 'tt13', 'link18')" onMouseOut="HideTip('tt13')">get_iterator</a></td><td class=SDescription><span class="virtual">virtual</span> Returns an iterator over the elements in this tree. </td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#tree.get_breadth_first_iterator" id=link19 onMouseOver="ShowTip(event, 'tt14', 'link19')" onMouseOut="HideTip('tt14')">get_breadth_first_iterator</a></td><td class=SDescription><span class="virtual">virtual</span> Returns a <a href="cl_tree_breadth_first_iterator-svh.html#tree_breadth_first_iterator" class=LClass id=link20 onMouseOver="ShowTip(event, 'tt15', 'link20')" onMouseOut="HideTip('tt15')">tree_breadth_first_iterator</a> over the elements in this tree.</td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#tree.get_last_node" id=link21 onMouseOver="ShowTip(event, 'tt16', 'link21')" onMouseOut="HideTip('tt16')">get_last_node</a></td><td class=SDescription><span class="virtual">virtual</span> Returns the last tree node in the breadth-first order.</td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#tree.update_locations" id=link22 onMouseOver="ShowTip(event, 'tt17', 'link22')" onMouseOut="HideTip('tt17')">update_locations</a></td><td class=SDescription><span class="virtual">virtual</span> Updates the <a href="cl_tree_node-svh.html#tree_node.location" class=LProperty id=link23 onMouseOver="ShowTip(event, 'tt18', 'link23')" onMouseOut="HideTip('tt18')">tree_node::location</a> of the entire tree.</td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#tree.get_location_name" id=link24 onMouseOver="ShowTip(event, 'tt19', 'link24')" onMouseOut="HideTip('tt19')">get_location_name</a></td><td class=SDescription><span class="virtual">virtual</span> Returns the human-readable location string of this node from the root. </td></tr></table></div></div><!--END_ND_SUMMARY--></div></div></div>

<div class="CGroup"><div class=CTopic><h3 class=CTitle><a name="tree.Types"></a>Types</h3></div></div>

<div class="CType"><div class=CTopic><h3 class=CTitle><a name="tree.tree_node_type"></a>tree_node_type</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>typedef tree_node#(</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PAfterParameters  prettyprint "nowrap>) tree_node_type</td></tr></table></td></tr></table></blockquote><p>The shorthand of the <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link25 onMouseOver="ShowTip(event, 'tt3', 'link25')" onMouseOut="HideTip('tt3')">tree_node</a> type specialized with type <b>T</b>.</p></div></div></div>

<div class="CType"><div class=CTopic><h3 class=CTitle><a name="tree.tree_type"></a>tree_type</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>typedef tree#(</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PAfterParameters  prettyprint "nowrap>) tree_type</td></tr></table></td></tr></table></blockquote><p>The shorthand of the <a href="#tree" class=LClass id=link26 onMouseOver="ShowTip(event, 'tt1', 'link26')" onMouseOut="HideTip('tt1')">tree</a> type specialized with type <b>T</b>.</p></div></div></div>

<div class="CGroup"><div class=CTopic><h3 class=CTitle><a name="tree.Properties"></a>Properties</h3></div></div>

<div class="CProperty"><div class=CTopic><h3 class=CTitle><a name="tree.root"></a>root</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td class="prettyprint">tree_node_type root</td></tr></table></blockquote><p>The root node of the tree.</p></div></div></div>

<div class="CGroup"><div class=CTopic><h3 class=CTitle><a name="tree.Functions"></a>Functions</h3></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.new"></a>new</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>function new(</td><td class="PType  prettyprint " nowrap>collection#(T)&nbsp;</td><td class="PParameter  prettyprint " nowrap>c</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> null,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>comparator#(T)&nbsp;</td><td class="PParameter  prettyprint " nowrap>cmp</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> null,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>formatter#(T)&nbsp;</td><td class="PParameter  prettyprint " nowrap>fmtr</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> null</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Creates a new tree.</p><h4 class=CHeading>Argument</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>c</td><td class=CDLDescription><span class="optional">optional</span> A collection whose elements are to be added to this tree.</td></tr><tr><td class=CDLEntry>cmp</td><td class=CDLDescription><span class="optional">optional</span> A strategy object used to compare the elements of type <b>T</b>.&nbsp; If not specified or <b>null</b>, <a href="cl_comparator-svh.html#comparator" class=LClass id=link27 onMouseOver="ShowTip(event, 'tt20', 'link27')" onMouseOut="HideTip('tt20')">comparator</a> <b>#(T)</b> is used.&nbsp; The default is <b>null</b>.</td></tr><tr><td class=CDLEntry>fmtr</td><td class=CDLDescription><span class="optional">optional</span> A strategy object that provides a function to convert the element of type <b>T</b> to a string.&nbsp; If not specified or <b>null</b>, <a href="cl_hex_formatter-svh.html#hex_formatter" class=LClass id=link28 onMouseOver="ShowTip(event, 'tt21', 'link28')" onMouseOut="HideTip('tt21')">hex_formatter</a> <b>#(T)</b> is used.&nbsp; The default is <b>null</b>.</td></tr></table><h4 class=CHeading>Example</h4><blockquote><pre class="prettyprint">tree#(int) int_tree = new();</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.add"></a>add</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function bit add(</td><td class="PType  prettyprint " nowrap>T&nbsp;</td><td class="PParameter  prettyprint " nowrap>e</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p><span class="virtual">virtual</span> Creates a new <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link29 onMouseOver="ShowTip(event, 'tt3', 'link29')" onMouseOut="HideTip('tt3')">tree_node</a> of the given element and adds it to the <a href="#tree.root" class=LProperty id=link30 onMouseOver="ShowTip(event, 'tt5', 'link30')" onMouseOut="HideTip('tt5')">root</a>.&nbsp;  If the <a href="#tree.root" class=LProperty id=link31 onMouseOver="ShowTip(event, 'tt5', 'link31')" onMouseOut="HideTip('tt5')">root</a> is empty, make the newly created <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link32 onMouseOver="ShowTip(event, 'tt3', 'link32')" onMouseOut="HideTip('tt3')">tree_node</a> as the root.</p><h4 class=CHeading>Argument</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>e</td><td class=CDLDescription>An element to be added to the <a href="#tree.root" class=LProperty id=link33 onMouseOver="ShowTip(event, 'tt5', 'link33')" onMouseOut="HideTip('tt5')">root</a>.</td></tr></table><h4 class=CHeading>Returns</h4><p>If this tree changed as a result of the call, 1 is returned.&nbsp; Otherwise, 0 is returned.</p><h4 class=CHeading>Example</h4><blockquote><pre class="prettyprint">tree#(int) int_tree = new();

assert( int_tree.add( 123 ) );
// (123)
//   \__ root node

assert( int_tree.add( 234 ) );
// (123) ---- (234)

assert( int_tree.add( 345 ) );
// (123) -+-- (234)
//        |
//        +-- (345)</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.add_to_node"></a>add_to_node</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function tree_node_type add_to_node(</td><td class="PType  prettyprint " nowrap>T&nbsp;</td><td class="PParameter  prettyprint " nowrap>e,</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%></td></tr><tr><td></td><td class="PType  prettyprint " nowrap>tree_node_type&nbsp;</td><td class="PParameter  prettyprint " nowrap>parent</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> null</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p><span class="virtual">virtual</span> Creates a new <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link34 onMouseOver="ShowTip(event, 'tt3', 'link34')" onMouseOut="HideTip('tt3')">tree_node</a> of the given element and adds it to the tree as the child of the specified parent.</p><h4 class=CHeading>Argument</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>e</td><td class=CDLDescription>An element to be added to the tree.</td></tr><tr><td class=CDLEntry>parent</td><td class=CDLDescription><span class="optional">optional</span> The parent <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link35 onMouseOver="ShowTip(event, 'tt3', 'link35')" onMouseOut="HideTip('tt3')">tree_node</a>.&nbsp; If the <b>parent</b> is <b>null</b>, add the node to the <a href="#tree.root" class=LProperty id=link36 onMouseOver="ShowTip(event, 'tt5', 'link36')" onMouseOut="HideTip('tt5')">root</a>.&nbsp; If the <a href="#tree.root" class=LProperty id=link37 onMouseOver="ShowTip(event, 'tt5', 'link37')" onMouseOut="HideTip('tt5')">root</a> is empty, make the newly created <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link38 onMouseOver="ShowTip(event, 'tt3', 'link38')" onMouseOut="HideTip('tt3')">tree_node</a> as the root.&nbsp; Default is <b>null</b>.</td></tr></table><h4 class=CHeading>Returns</h4><p>Newly added <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link39 onMouseOver="ShowTip(event, 'tt3', 'link39')" onMouseOut="HideTip('tt3')">tree_node</a>.</p><h4 class=CHeading>Example</h4><blockquote><pre class="prettyprint">tree#(int)      int_tree = new();
tree_node#(int) tn_123;
tree_node#(int) tn_234;
tree_node#(int) tn_345;

tn_123 = int_tree.add_to_node( 123 );
// (123)
//   \__ root node

tn_234 = int_tree.add_to_node( 234, .parent( tn_123 ) );
// (123) ---- (234)

tn_345 = int_tree.add_to_node( 345, .parent( tn_234 ) );
// (123) ---- (234) ---- (345)</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.graft"></a>graft</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function tree_node_type graft(</td><td class="PType  prettyprint " nowrap>tree_node_type&nbsp;</td><td class="PParameter  prettyprint " nowrap>tn,</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%></td></tr><tr><td></td><td class="PType  prettyprint " nowrap>tree_node_type&nbsp;</td><td class="PParameter  prettyprint " nowrap>parent</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> null</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p><span class="virtual">virtual</span> Grafts the given <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link40 onMouseOver="ShowTip(event, 'tt3', 'link40')" onMouseOut="HideTip('tt3')">tree_node</a> (and its children) to the tree as the child of the specified parent.</p><h4 class=CHeading>Argument</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>tn</td><td class=CDLDescription>A tree node to be grafted.</td></tr><tr><td class=CDLEntry>parent</td><td class=CDLDescription><span class="optional">optional</span> The parent <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link41 onMouseOver="ShowTip(event, 'tt3', 'link41')" onMouseOut="HideTip('tt3')">tree_node</a>.&nbsp; If the <b>parent</b> is <b>null</b>, add the node to the <a href="#tree.root" class=LProperty id=link42 onMouseOver="ShowTip(event, 'tt5', 'link42')" onMouseOut="HideTip('tt5')">root</a>.&nbsp; If the <a href="#tree.root" class=LProperty id=link43 onMouseOver="ShowTip(event, 'tt5', 'link43')" onMouseOut="HideTip('tt5')">root</a> is empty, make the <b>tn</b> as the root.&nbsp; Default is <b>null</b>.</td></tr></table><h4 class=CHeading>Returns</h4><p>A tree node to be grafted (<b>tn</b>).</p><h4 class=CHeading>Example</h4><blockquote><pre class="prettyprint">tree#(int)      int_tree = new();
tree_node#(int) tn;
tree_node#(int) tn_123;
tree_node#(int) tn_234;
tree_node#(int) tn_345;
tree_node#(int) tn_456;

tn_123 = int_tree.add_to_node( 123 );
tn_234 = int_tree.add_to_node( 234, .parent( tn_123 ) );
// (123) ---- (234)
//              \__ tn_234

tn_345 = new( 345 );
tn_456 = tn_345.add( 456 );
// (345) ---- (456)
//   \__ tn_345

tn = int_tree.graft( tn_345, .parent( tn_234 ) );
// (123) ---- (234) ---- (345) --- (456)
//                         \__ tn</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.clear"></a>clear</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td class="prettyprint">virtual function void clear()</td></tr></table></blockquote><p><span class="virtual">virtual</span> Removes all of the elements from this tree.</p><h4 class=CHeading>Returns</h4><p>None.</p><h4 class=CHeading>Example</h4><blockquote><pre class="prettyprint">tree#(int) int_tree = new();

assert( int_tree.add( 123 ) );
assert( int_tree.add( 234 ) );
assert( int_tree.size() == 2 );
int_tree.clear();
assert( int_tree.size() == 0 );</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.clone"></a>clone</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function collection#(</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PAfterParameters  prettyprint "nowrap>) clone()</td></tr></table></td></tr></table></blockquote><p><span class="virtual">virtual</span> Returns a shallow copy of this tree.&nbsp; Only the <a href="#tree.root" class=LProperty id=link44 onMouseOver="ShowTip(event, 'tt5', 'link44')" onMouseOut="HideTip('tt5')">root</a> is copied.&nbsp; The children are not cloned.</p><h4 class=CHeading>Returns</h4><p>A copy of this tree.</p><h4 class=CHeading>Example</h4><blockquote><pre class="prettyprint">tree#(int) int_tree = new();
collection#(int) cloned;

assert( int_tree.add( 123 ) );
assert( int_tree.add( 234 ) );
cloned = int_tree.clone();
assert( cloned.size() == 2 );</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.is_empty"></a>is_empty</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td class="prettyprint">virtual function bit is_empty()</td></tr></table></blockquote><p><span class="virtual">virtual</span> Returns 1 if this tree contains no elements.</p><h4 class=CHeading>Returns</h4><p>If this tree contains no elements, returns 1.&nbsp; Otherwise, returns 0.</p><h4 class=CHeading>Example</h4><blockquote><pre class="prettyprint">tree#(int) int_tree = new();

assert( int_tree.add( 123 ) );
assert( int_tree.add( 234 ) );
assert( int_tree.is_empty() == 0 );</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.get_iterator"></a>get_iterator</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function iterator#(</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PAfterParameters  prettyprint "nowrap>) get_iterator()</td></tr></table></td></tr></table></blockquote><p><span class="virtual">virtual</span> Returns an iterator over the elements in this tree.&nbsp; This function is equivalent to <a href="#tree.get_breadth_first_iterator" class=LFunction id=link45 onMouseOver="ShowTip(event, 'tt14', 'link45')" onMouseOut="HideTip('tt14')">get_breadth_first_iterator</a>.</p><h4 class=CHeading>Returns</h4><p>An iterator.</p><h4 class=CHeading>Example</h4><blockquote><pre class="prettyprint">tree#(int)      int_tree = new();
tree_node#(int) tn_123;
tree_node#(int) tn_234;
tree_node#(int) tn_345;
tree_node#(int) tn_456;
iterator#(int)  it;
string s;

tn_123 = int_tree.add_to_node( 123 );
tn_234 = int_tree.add_to_node( 234, .parent( tn_123 ) );
tn_345 = int_tree.add_to_node( 345, .parent( tn_123 ) );
tn_456 = int_tree.add_to_node( 456, .parent( tn_234 ) );
// (123) -+-- (234) ---- (456)
//        |
//        +-- (345)

it = int_tree.get_iterator();
while ( it.has_next() ) s = { s, $sformatf( &quot;%0d &quot;, it.next() ) };
assert( s == &quot;123 234 345 456 &quot; );</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.get_breadth_first_iterator"></a>get_breadth_first_iterator</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function iterator#(</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PAfterParameters  prettyprint "nowrap>) get_breadth_first_iterator()</td></tr></table></td></tr></table></blockquote><p><span class="virtual">virtual</span> Returns a <a href="cl_tree_breadth_first_iterator-svh.html#tree_breadth_first_iterator" class=LClass id=link46 onMouseOver="ShowTip(event, 'tt15', 'link46')" onMouseOut="HideTip('tt15')">tree_breadth_first_iterator</a> over the elements in this tree.</p><h4 class=CHeading>Returns</h4><p>An iterator.</p><h4 class=CHeading>Example</h4><blockquote><pre class="prettyprint">tree#(int)      int_tree = new();
tree_node#(int) tn_123;
tree_node#(int) tn_234;
tree_node#(int) tn_345;
tree_node#(int) tn_456;
iterator#(int)  it;
string s;

tn_123 = int_tree.add_to_node( 123 );
tn_234 = int_tree.add_to_node( 234, .parent( tn_123 ) );
tn_345 = int_tree.add_to_node( 345, .parent( tn_123 ) );
tn_456 = int_tree.add_to_node( 456, .parent( tn_234 ) );
// (123) -+-- (234) ---- (456)
//        |
//        +-- (345)

it = int_tree.get_breadth_first_iterator();
while ( it.has_next() ) s = { s, $sformatf( &quot;%0d &quot;, it.next() ) };
assert( s == &quot;123 234 345 456 &quot; );</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.get_last_node"></a>get_last_node</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td class="prettyprint">virtual function tree_node_type get_last_node()</td></tr></table></blockquote><p><span class="virtual">virtual</span> Returns the last tree node in the breadth-first order.</p><h4 class=CHeading>Returns</h4><p>The last node.&nbsp; If the last tree node does not exist, returns <b>null</b>.</p><h4 class=CHeading>Example</h4><blockquote><pre class="prettyprint">tree#(int) int_tree = new();
assert( int_tree.add( 123 ) );
assert( int_tree.add( 234 ) );

assert( int_tree.get_last_node().elem == 234 );</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.update_locations"></a>update_locations</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td class="prettyprint">virtual function void update_locations()</td></tr></table></blockquote><p><span class="virtual">virtual</span> Updates the <a href="cl_tree_node-svh.html#tree_node.location" class=LProperty id=link47 onMouseOver="ShowTip(event, 'tt18', 'link47')" onMouseOut="HideTip('tt18')">tree_node::location</a> of the entire tree.</p><h4 class=CHeading>Returns</h4><p>None.</p></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="tree.get_location_name"></a>get_location_name</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function string get_location_name(</td><td class="PType  prettyprint " nowrap>tree_node_type&nbsp;</td><td class="PParameter  prettyprint " nowrap>tn</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p><span class="virtual">virtual</span> Returns the human-readable location string of this node from the root.&nbsp; The user must call <a href="#tree.update_locations" class=LFunction id=link48 onMouseOver="ShowTip(event, 'tt17', 'link48')" onMouseOut="HideTip('tt17')">update_locations</a> prior to this function if the tree structure has changed since the last call of this function (this function does not call <a href="#tree.update_locations" class=LFunction id=link49 onMouseOver="ShowTip(event, 'tt17', 'link49')" onMouseOut="HideTip('tt17')">update_locations</a> by itself).&nbsp; See <a href="cl_tree_node-svh.html#tree_node.location" class=LProperty id=link50 onMouseOver="ShowTip(event, 'tt18', 'link50')" onMouseOut="HideTip('tt18')">tree_node::location</a> for more detail.</p><h4 class=CHeading>Argument</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>tn</td><td class=CDLDescription>The <a href="cl_tree_node-svh.html#tree_node" class=LClass id=link51 onMouseOver="ShowTip(event, 'tt3', 'link51')" onMouseOut="HideTip('tt3')">tree_node</a> to get its location name.</td></tr></table><h4 class=CHeading>Returns</h4><p>The location string.</p><h4 class=CHeading>Example</h4><blockquote><pre class="prettyprint">tree#(int)      t = new();
tree_node#(int) tn_234;
tree_node#(int) tn_345;
tree_node#(int) tn_456;
tree_node#(int) tn_567;
tree_node#(int) root;

root = t.add_to_node( 123 );
tn_234 = t.add_to_node( 234 );
tn_345 = t.add_to_node( 345 );
tn_456 = t.add_to_node( 456 );
tn_567 = t.add_to_node( 567, .parent( tn_456 ) );
// (123) -+-- (234)
//        |
//        +-- (345)
//        |
//        +-- (456) ---- (567)

t.update_locations();
assert( t.get_location_name( tn_567 ) == &quot;[0,2,0]&quot; );</pre></blockquote><h4 class=CHeading>See Also</h4><p><a href="cl_tree_node-svh.html#tree_node.location" class=LProperty id=link52 onMouseOver="ShowTip(event, 'tt18', 'link52')" onMouseOut="HideTip('tt18')">tree_node::location</a></p></div></div></div>

</div><!--Content-->



<!--START_ND_TOOLTIPS-->
<div class=CToolTip id="tt1"><div class=CClass><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>class tree #(</td><td class="PType  prettyprint " nowrap>type&nbsp;</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> int</td><td class="PAfterParameters  prettyprint "nowrap>) extends collection#( T )</td></tr></table></td></tr></table></blockquote>Implements a tree structure.</div></div><div class=CToolTip id="tt2"><div class=CType><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>typedef tree_node#(</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PAfterParameters  prettyprint "nowrap>) tree_node_type</td></tr></table></td></tr></table></blockquote>The shorthand of the tree_node type specialized with type <b>T</b>.</div></div><div class=CToolTip id="tt3"><div class=CClass><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>class tree_node #(</td><td class="PType  prettyprint " nowrap>type&nbsp;</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> int</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>Implements a node of a tree.</div></div><div class=CToolTip id="tt4"><div class=CType><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>typedef tree#(</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PAfterParameters  prettyprint "nowrap>) tree_type</td></tr></table></td></tr></table></blockquote>The shorthand of the tree type specialized with type <b>T</b>.</div></div><div class=CToolTip id="tt5"><div class=CProperty><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td class="prettyprint">tree_node_type root</td></tr></table></blockquote>The root node of the tree.</div></div><div class=CToolTip id="tt6"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>function new(</td><td class="PType  prettyprint " nowrap>collection#(T)&nbsp;</td><td class="PParameter  prettyprint " nowrap>c</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> null,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>comparator#(T)&nbsp;</td><td class="PParameter  prettyprint " nowrap>cmp</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> null,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>formatter#(T)&nbsp;</td><td class="PParameter  prettyprint " nowrap>fmtr</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> null</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>Creates a new tree.</div></div><div class=CToolTip id="tt7"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function bit add(</td><td class="PType  prettyprint " nowrap>T&nbsp;</td><td class="PParameter  prettyprint " nowrap>e</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><span class="virtual">virtual</span> Creates a new tree_node of the given element and adds it to the root. </div></div><div class=CToolTip id="tt8"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function tree_node_type add_to_node(</td><td class="PType  prettyprint " nowrap>T&nbsp;</td><td class="PParameter  prettyprint " nowrap>e,</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%></td></tr><tr><td></td><td class="PType  prettyprint " nowrap>tree_node_type&nbsp;</td><td class="PParameter  prettyprint " nowrap>parent</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> null</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><span class="virtual">virtual</span> Creates a new tree_node of the given element and adds it to the tree as the child of the specified parent.</div></div><div class=CToolTip id="tt9"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function tree_node_type graft(</td><td class="PType  prettyprint " nowrap>tree_node_type&nbsp;</td><td class="PParameter  prettyprint " nowrap>tn,</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%></td></tr><tr><td></td><td class="PType  prettyprint " nowrap>tree_node_type&nbsp;</td><td class="PParameter  prettyprint " nowrap>parent</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> null</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><span class="virtual">virtual</span> Grafts the given tree_node (and its children) to the tree as the child of the specified parent.</div></div><div class=CToolTip id="tt10"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td class="prettyprint">virtual function void clear()</td></tr></table></blockquote><span class="virtual">virtual</span> Removes all of the elements from this tree.</div></div><div class=CToolTip id="tt11"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function collection#(</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PAfterParameters  prettyprint "nowrap>) clone()</td></tr></table></td></tr></table></blockquote><span class="virtual">virtual</span> Returns a shallow copy of this tree. </div></div><div class=CToolTip id="tt12"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td class="prettyprint">virtual function bit is_empty()</td></tr></table></blockquote><span class="virtual">virtual</span> Returns 1 if this tree contains no elements.</div></div><div class=CToolTip id="tt13"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function iterator#(</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PAfterParameters  prettyprint "nowrap>) get_iterator()</td></tr></table></td></tr></table></blockquote><span class="virtual">virtual</span> Returns an iterator over the elements in this tree. </div></div><div class=CToolTip id="tt14"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function iterator#(</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PAfterParameters  prettyprint "nowrap>) get_breadth_first_iterator()</td></tr></table></td></tr></table></blockquote><span class="virtual">virtual</span> Returns a tree_breadth_first_iterator over the elements in this tree.</div></div><div class=CToolTip id="tt15"><div class=CClass><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>class tree_breadth_first_iterator #(</td><td class="PType  prettyprint " nowrap>type&nbsp;</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> int</td><td class="PAfterParameters  prettyprint "nowrap>) extends iterator#( T )</td></tr></table></td></tr></table></blockquote>Provides a breadth-first iterator to a tree.</div></div><div class=CToolTip id="tt16"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td class="prettyprint">virtual function tree_node_type get_last_node()</td></tr></table></blockquote><span class="virtual">virtual</span> Returns the last tree node in the breadth-first order.</div></div><div class=CToolTip id="tt17"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td class="prettyprint">virtual function void update_locations()</td></tr></table></blockquote><span class="virtual">virtual</span> Updates the tree_node::location of the entire tree.</div></div><div class=CToolTip id="tt18"><div class=CProperty><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td class="prettyprint">int location[$]</td></tr></table></blockquote>The queue indicating the location of this tree node in a tree. </div></div><div class=CToolTip id="tt19"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>virtual function string get_location_name(</td><td class="PType  prettyprint " nowrap>tree_node_type&nbsp;</td><td class="PParameter  prettyprint " nowrap>tn</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><span class="virtual">virtual</span> Returns the human-readable location string of this node from the root. </div></div><div class=CToolTip id="tt20"><div class=CClass><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>class comparator#(</td><td class="PType  prettyprint " nowrap>type&nbsp;</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> int</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><span class="singleton">singleton</span> Provides strategies to compare objects.</div></div><div class=CToolTip id="tt21"><div class=CClass><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>class hex_formatter #(</td><td class="PType  prettyprint " nowrap>type&nbsp;</td><td class="PParameter  prettyprint " nowrap>T</td><td class="PDefaultValuePrefix  prettyprint ">&nbsp;=&nbsp;</td><td class="PDefaultValue  prettyprint " width=100%> int</td><td class="PAfterParameters  prettyprint "nowrap>) extends formatter#( T )</td></tr></table></td></tr></table></blockquote><span class="singleton">singleton</span> Provides a strategy to convert an object of type <b>T</b> to a string using a hexadecimal format.</div></div><!--END_ND_TOOLTIPS-->

<script language=JavaScript><!--
if (browserType) {if (browserVer) {document.write("</div>"); }document.write("</div>");}// --></script></body></html>